import request from '@/utils/request'
// import qs from 'qs'

// 静态DNS

// 获取静态DNS列表
export function getHostsArray (params) {
  var data = fromData(params)
  return request({
    url: '/dns/getHostsArray',
    method: 'post',
    data
  })
}

// 设置静态DNS
export function setHostsInfo (params) {
  var data = fromData(params)
  return request({
    url: '/dns/setHostsInfo',
    method: 'post',
    data
  })
}

// 删除信息
export function delHostsInfo (params) {
  var data = fromData(params)
  return request({
    url: '/dns/del_hosts_info',
    method: 'post',
    data
  })
}

// 清空静态DNS配置
export function clearHosts (params) {
  var data = fromData(params)
  return request({
    url: '/dns/clearHosts',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
